﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Xml;
using Castle.Core;
using Castle.Windsor;
using Castle.Windsor.Configuration;
using Castle.MicroKernel.Registration;
namespace DomainModelDemo.UI.Web
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            using (IWindsorContainer container = new WindsorContainer())
            {
                container.Register(Component.For<IPerson>().ImplementedBy<Student>());
                var student = container.Resolve<IPerson>();
                Response.Write(student.ShowName());
            }
           
            //PersonService service = new PersonService();
            //service.Person = new Student();
            //string result=service.ShowName();
            //Response.Write(result);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            using (FileStream stream = File.Open(Server.MapPath("data.txt"), FileMode.OpenOrCreate))
            {
                using (StreamWriter wr = new StreamWriter(stream, System.Text.Encoding.UTF8))
                {
                    wr.Write("HH");
                    wr.Flush();
                    wr.Close();
                }
            }          
        }
        #region Add SEO Info
        private string GetXmlContent(int nodeIndex)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(Server.MapPath("SEO.xml"));
            XmlNode keywordsNode = xmlDoc.DocumentElement.ChildNodes[nodeIndex];
            string content = "";
            if (keywordsNode != null)
            {
                content = keywordsNode["Content"].InnerText;
            }
            return content;
        }
        protected override void OnPreRender(EventArgs e)
        {

            HtmlMeta keyWords = new HtmlMeta();
            keyWords.Name = "KeyWords";
            keyWords.Content = GetXmlContent(0);
            Page.Header.Controls.AddAt(1, keyWords);

            Page.Title = " 财经资讯-数米基金网";

            HtmlMeta description = new HtmlMeta();
            description.Name = "Description";
            description.Content = GetXmlContent(1);
            Page.Header.Controls.AddAt(2, description);
        }
        #endregion
    }
}